package com.ra.util;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.espirit.eap.sa.LoginUser;
import com.espirit.eap.sa.LoginUserService;
import com.googlecode.cswish.annotation.Rest;
import com.googlecode.cswish.struts.spring.GenericService;

/**
 * 意见反馈服务
 * 
 * @author colin
 * @date 2015年5月16日
 *
 */
@Service
public class FeedbackService {
	
	@Resource
	private GenericService genericService;
	
	@Resource
	private LoginUserService loginUserService;
	
	/**
	 * 查询意见反馈列表
	 * @param model
	 * @return
	 */
	@Rest(type = "search")
	public List<Feedback> searchFeedback(Feedback model){
		List<Feedback> feedbacks = genericService.searchAll(model).getData();
		if (feedbacks == null) {
			feedbacks = new ArrayList<>();
		}
		return feedbacks;
	}
	
	/**
	 * 新增意见反馈
	 * @param model
	 * @return
	 */
	@Rest(simpleServiceName = "anonymity", type = "free")
	public Feedback addFeedback(Feedback model){
		LoginUser loginUser = loginUserService.getLoginUser();
		model.setLoginUser(loginUser);
		model.setStatus(Feedback.STATUS_ADD);
		model.setCreateTime(Calendar.getInstance().getTime());
		return genericService.add(model);
	}
	
}
